/*     */ package com.kingdee.eas.lifetime.util.DButil;
/*     */ 
/*     */ import com.kingdee.bos.ui.face.CoreUIObject;
/*     */ import java.io.File;
/*     */ import java.io.IOException;
/*     */ import java.io.InputStream;
/*     */ import java.util.List;
/*     */ import org.apache.log4j.Logger;
/*     */ import org.jdom.Attribute;
/*     */ import org.jdom.Document;
/*     */ import org.jdom.Element;
/*     */ import org.jdom.JDOMException;
/*     */ import org.jdom.input.SAXBuilder;
/*     */ 
/*     */ public class EDsqlReader
/*     */ {
/*  31 */   static final Logger logger = CoreUIObject.getLogger(EDsqlReader.class);
/*     */ 
/*  33 */   private static EDsqlReader reader = null;
/*     */   private static final String sql_sign = "sql";
/*     */   private static final String sql_sign_att_queryName = "name";
/*     */ 
/*     */   public static EDsqlReader getInstance()
/*     */   {
/*  46 */     if (reader == null) {
/*  47 */       reader = new EDsqlReader();
/*     */     }
/*  49 */     return reader;
/*     */   }
/*     */ 
/*     */   public EDsqlResult getSql(String sqlXmlFilePath, String sqlName)
/*     */   {
/*  62 */     SAXBuilder builder = new SAXBuilder();
/*     */     try {
/*  64 */       Document document = builder.build(new File(sqlXmlFilePath));
/*  65 */       return getSql(document, sqlName);
/*     */     } catch (JDOMException e) {
/*  67 */       e.printStackTrace();
/*     */     } catch (IOException e) {
/*  69 */       e.printStackTrace();
/*     */     }
/*  71 */     return null;
/*     */   }
/*     */ 
/*     */   public EDsqlResult getSql(InputStream stream, String sqlName)
/*     */   {
/*  84 */     SAXBuilder builder = new SAXBuilder();
/*     */     try {
/*  86 */       Document document = builder.build(stream);
/*  87 */       return getSql(document, sqlName);
/*     */     } catch (JDOMException e) {
/*  89 */       e.printStackTrace();
/*     */     } catch (IOException e) {
/*  91 */       e.printStackTrace();
/*     */     }
/*  93 */     return null;
/*     */   }
/*     */ 
/*     */   private EDsqlResult getSql(Document document, String sqlName) {
/*  97 */     Element element = document.getRootElement();
/*  98 */     List lists = element.getChildren("sql");
/*  99 */     int i = lists.size();
/*     */     do { Element ele = (Element)lists.get(i);
/* 101 */       Attribute attribute = ele.getAttribute("name");
/* 102 */       if ((attribute != null) && (sqlName.equals(attribute.getValue())))
/* 103 */         return new EDsqlResult(ele.getText());
/*  99 */       i--; } while (i >= 0);
/*     */ 
/* 106 */     return null;
/*     */   }
/*     */ }

/* Location:           D:\work\kingdee\enable\富国基金\fuguo_lib.jar
 * Qualified Name:     com.kingdee.eas.lifetime.util.DButil.EDsqlReader
 * JD-Core Version:    0.6.0
 */